//给某个input应用市场选择器
//参考mediaForm.jsp
$.fn.market = function(){
	var $this = $(this);
	$this.on('click', function(){
		var oldValue = $this.val();
		
		var setting = {
			view:{
				showIcon: false
			},
			check: {
				enable: true,
				chkboxType: { "Y" : "", "N" : "" }
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onCheck: onCheck
			}
		};
		
		function onCheck(e, treeId, treeNode) {
			setHidden();
		}
		
		function setHidden(){
		}
		
		var zNodes = marketList;
		
		for(var i = 0; i < zNodes.length; i++){
			var node = zNodes[i];
			if(oldValue.indexOf("[" + node.name + "]") != -1){
				node.checked = true;
			}else{
				node.checked = false;
			}
		}
	
		//初始化树复选框
		$.fn.zTree.init($("#market_tree"), setting, zNodes);
		
		//显示模态窗口
		$('#market-modal').modal({
			backdrop: "static"
		});
		
		//市场选择完成时触发
		$("#marketDecide").unbind("click");
		$("#marketDecide").click(function(){
			var value = "";
			var zTree = $.fn.zTree.getZTreeObj("market_tree");
			var nodes = zTree.getCheckedNodes(true);
			for(var i = 0; i < nodes.length; i++){
				var n = nodes[i];
				value += ("[" + n.name + "]");
			}
			$this.val(value);
			$("#market-modal").modal("hide");
		});
	});
	
}